﻿<%@ Page Title="" Language="C#" MasterPageFile="~/AdminTemplate.Master" AutoEventWireup="true" CodeBehind="ManageAccount.aspx.cs" Inherits="EnglishAuction.ManageAccount" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    Quản lý tài khoản
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <style type="text/css">
        .ui-widget {
            font-size: 13px !important;
        }

        .ui-state-error-text {
            margin-left: 10px;
            color: red;
        }
    </style>
    <script>
        $(document).ready(function () {
            $("#divEditCustomer").dialog({
                autoOpen: false,
                modal: true,
                minHeight: 20,
                height: 'auto',
                width: 'auto',
                resizable: false,
                open: function (event, ui) {
                    $(this).parent().appendTo("#divEditCustomerDlgContainer");
                },
            });

            $("#div2").dialog({
                autoOpen: false,
                modal: true,
                minHeight: 20,
                height: 'auto',
                width: 'auto',
                resizable: false,
                open: function (event, ui) {
                    $(this).parent().appendTo("#div1");
                },
            });
        });

        function closeDialog2() {
            //Could cause an infinite loop because of "on close handling"
            $("#div2").dialog('close');
        }

        function openDialog2(title, linkID) {

            var pos = $("#" + linkID).position();
            //var top = pos.top;
            //var left = pos.left + $("#" + linkID).width() + 10;


            $("#div2").dialog("option", "title", title);
            //$("#divEditCustomer").dialog("option", "position", [left, top]);

            $("#div2").dialog('open');
        }

        function openDialogAndBlock2(title, linkID) {
            openDialog2(title, linkID);

            //block it to clean out the data
            $("#div2").block({
                message: '<img src="<%=ResolveUrl("~") %>images/async.gif" />',
                css: { border: '0px' },
                fadeIn: 0,
                //fadeOut: 0,
                overlayCSS: { backgroundColor: '#ffffff', opacity: 1 }
            });
            //unblockDialog2();
        }

        function unblockDialog2() {
            $("#div2").unblock();
        }

        function closeDialog() {
            //Could cause an infinite loop because of "on close handling"
            $("#divEditCustomer").dialog('close');
        }

        function openDialog(title, linkID) {

            var pos = $("#" + linkID).position();
            //var top = pos.top;
            //var left = pos.left + $("#" + linkID).width() + 10;


            $("#divEditCustomer").dialog("option", "title", title);
            //$("#divEditCustomer").dialog("option", "position", [left, top]);

            $("#divEditCustomer").dialog('open');
        }

        function openDialogAndBlock(title, linkID) {
            openDialog(title, linkID);

            //block it to clean out the data
            $("#divEditCustomer").block({
                message: '<img src="<%=ResolveUrl("~") %>images/async.gif" />',
                css: { border: '0px' },
                fadeIn: 0,
                //fadeOut: 0,
                overlayCSS: { backgroundColor: '#ffffff', opacity: 1 }
            });
            unblockDialog();
        }

        function unblockDialog() {
            $("#divEditCustomer").unblock();
        }


    </script>

    <form id="form1" runat="server">
        <br />
        <asp:ScriptManager ID="scriptManager" runat="server" />
        <div style="border: solid 1px; background-color: #FFF; border-radius: 5px; border-color: #CCCCCC; width: 100%;">
            <div id="divEditCustomerDlgContainer">
                <div id="divEditCustomer" style="display: none">

                    <asp:UpdatePanel ID="upnlEditCustomer" runat="server">
                        <ContentTemplate>
                            <asp:PlaceHolder ID="phrEditCustomer" runat="server">
                                <table cellpadding="3" cellspacing="1">
                                    <tr>
                                        <td>&nbsp;</td>
                                        <td>
                                            <div>
                                                <asp:Label ID="txtError" runat="server" ForeColor="Red" Font-Bold="true" />
                                            </div>

                                        </td>
                                    </tr>
                                    <tr>
                                        <td>Tên tài khoản:
                                        </td>
                                        <td>
                                            <asp:TextBox ID="txtTenTaiKhoan" Columns="40" MaxLength="32" runat="server"  />
                                            <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="Tài khoản không được bỏ trống." Font-Bold="true" ForeColor="Red" ControlToValidate="txtTenTaiKhoan" SetFocusOnError="true"></asp:RequiredFieldValidator>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>Mật khẩu:
                                        </td>
                                        <td>
                                            <asp:TextBox ID="txtMatKhau" Columns="40" MaxLength="32" runat="server" TextMode="Password"  />
                                            <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="Mật khẩu không được bỏ trống." Font-Bold="true" ForeColor="Red" ControlToValidate="txtMatKhau" SetFocusOnError="true"></asp:RequiredFieldValidator>
                                        </td>
                                    </tr>

                                    <tr>
                                        <td>Họ tên:
                                        </td>
                                        <td>
                                            <asp:TextBox ID="txtHoTen" Columns="40" MaxLength="100" runat="server" />
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>Số điện thoại:
                                        </td>
                                        <td>
                                            <asp:TextBox ID="txtSoDienThoai" Columns="40" MaxLength="100" runat="server" />
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>Giới tính:
                                        </td>
                                        <td>
                                            <asp:RadioButton ID="rbNam" runat="server" Checked="true" GroupName="gioiTinh" />
                                            Nam
                                                <asp:RadioButton ID="rbNu" runat="server" GroupName="gioiTinh" />
                                            Nữ
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>Địa chỉ:
                                        </td>
                                        <td>
                                            <asp:TextBox runat="server" ID="txtDiaChi" Columns="40" MaxLength="100"></asp:TextBox>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>Loại nhân viên:
                                        </td>
                                        <td>
                                            <asp:DropDownList ID="cboLoaiNhanVien" Columns="20" runat="server" />   
                                            <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ErrorMessage="Loại nhân viên chưa được chọn." Font-Bold="true" ForeColor="Red" ControlToValidate="cboLoaiNhanVien" SetFocusOnError="true" InitialValue="-1"></asp:RequiredFieldValidator>  
                                        </td>
                                    </tr>

                                    <tr>
                                        <td colspan="2" align="right">
                                            <asp:Button ID="btnSave" OnClick="btnSave_Click" Text="Lưu" runat="server" CssClass="button"/>
                                            <asp:Button ID="btnCancel" OnClick="btnCancel_Click" OnClientClick="closeDialog()" CausesValidation="false" Text="Hủy" runat="server" CssClass="button" />
                                        </td>
                                    </tr>
                                </table>
                            </asp:PlaceHolder>
                        </ContentTemplate>
                    </asp:UpdatePanel>
                </div>
            </div>

            <!-- divEditCustomerDlgContainer -->
            <!--??--->
            <div id="div1">
                <div id="div2" style="display: none">
                    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                        <ContentTemplate>
                            <asp:PlaceHolder ID="PlaceHolder1" runat="server">
                                <table cellpadding="3" cellspacing="1">
                                    <tr>
                                        <td>&nbsp;</td>
                                        <td>
                                            <div>
                                                <asp:Label ID="Label1" runat="server" ForeColor="Red" Font-Bold="true" />
                                            </div>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>Tên tài khoản:
                                        </td>
                                        <td>
                                            <asp:TextBox ID="txtAccount" Columns="40" MaxLength="32" runat="server" Enabled="false" />
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>Mật khẩu:
                                        </td>
                                        <td>
                                            <asp:TextBox ID="txtPassword" Columns="40" MaxLength="32" runat="server" TextMode="Password" />
                                        </td>
                                    </tr>

                                    <tr>
                                        <td>Họ tên:
                                        </td>
                                        <td>
                                            <asp:TextBox ID="txtFullName" Columns="40" MaxLength="100" runat="server" />
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>Số điện thoại:
                                        </td>
                                        <td>
                                            <asp:TextBox ID="txtPhoneNumber" Columns="40" MaxLength="100" runat="server" />
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>Giới tính:
                                        </td>
                                        <td>
                                            <asp:RadioButton ID="rdMale" runat="server" Checked="true" GroupName="gioiTinh2" />
                                            Nam
                                                <asp:RadioButton ID="rdFemale" runat="server" GroupName="gioiTinh2" />
                                            Nữ
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>Địa chỉ:
                                        </td>
                                        <td>
                                            <asp:TextBox runat="server" ID="txtAddress" Columns="40" MaxLength="100"></asp:TextBox>
                                        </td>
                                    </tr>
                                    </tr>

                                    <tr>
                                        <td colspan="2" align="right">
                                            <asp:Button ID="btnS" OnClick="btnS_Click" Text="Lưu" runat="server" CausesValidation="false" CssClass="button" />
                                            <asp:Button ID="btnCancel1" OnClick="btnCancel_Click1" OnClientClick="closeDialog2()" Text="Hủy" runat="server" CssClass="button" />
                                        </td>
                                    </tr>
                                </table>
                            </asp:PlaceHolder>
                        </ContentTemplate>
                    </asp:UpdatePanel>
                </div>
            </div>
            <div style="font-size: 20px; padding: 10px;">
                Quản lý nhân viên
            </div>
            <hr style="border-style: inset; border-width: 1px; width: 98%;" />
            <asp:UpdatePanel ID="upnlCustomers" UpdateMode="Conditional" runat="server">
                <ContentTemplate>
                    <asp:LinkButton ID="btnAddCustomer" Text="Thêm mới nhân viên" runat="server" OnClientClick="openDialogAndBlock('Thêm mới nhân viên', 'btnAddCustomer')" CausesValidation="false" OnClick="btnAddCustomer_Click" CssClass="button big icon user" Style="margin-left: 50px;"></asp:LinkButton>
                    <br />
                    <br />
                    <div style="overflow: auto; width: 1000px; margin: 0 auto;">
                        <asp:GridView ID="gvCustomers" runat="server"
                            AutoGenerateColumns="False" CellPadding="4" CellSpacing="1"
                            OnRowDataBound="gvCustomers_RowDataBound"
                            OnRowCommand="gvCustomers_RowCommand"
                            HeaderStyle-BackColor="#eeeeee"
                            Style="border: 1px solid #D8D8D8; background-color: #ffffff;"
                            Width="100%">
                            <Columns>
                                <asp:TemplateField HeaderText="STT" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" ItemStyle-Width="50">
                                    <ItemTemplate>
                                        <%# Container.DataItemIndex + 1 %>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="Tài khoản">
                                    <ItemTemplate>
                                        <%# Eval("TaiKhoan")%>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:BoundField DataField="HoTen" HeaderText="Họ tên" />
                                <asp:TemplateField HeaderText="Giới tính" SortExpression="Active" ItemStyle-Width="100" ItemStyle-HorizontalAlign="Center">
                                    <ItemTemplate><%# (Boolean.Parse(Eval("GioiTinh").ToString())) ? "Nam" : "Nữ" %></ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="Số điện thoại">
                                    <ItemTemplate>
                                        <%# Eval("SoDienThoai")%>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="Địa chỉ">
                                    <ItemTemplate>
                                        <%# Eval("DiaChi")%>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField>
                                    <ItemTemplate>
                                        <asp:ImageButton ImageUrl="~/images/edit_icon.png" Width="20" Height="20" ID="btnUp" Text="Update" CommandName="EditCustomer" CausesValidation="false" CommandArgument='<%#Eval("Id")%>' runat="server"></asp:ImageButton> &nbsp;&nbsp;
                                        <asp:ImageButton ImageUrl="~/images/delete_icon.png" Width="20" Height="20" ID="btnDelete" Text="Delete" CommandName="DeleteCustomer" CausesValidation="false" CommandArgument='<%#Eval("Id")%>' runat="server" OnClientClick="return confirm('Chắc chắn xóa nhân viên này?');"></asp:ImageButton>
                                    </ItemTemplate>
                                </asp:TemplateField>
                            </Columns>
                        </asp:GridView>
                    </div>
                    <asp:LinkButton ID="btnRefreshGrid" CausesValidation="false" OnClick="btnRefreshGrid_Click" Style="display: none" runat="server"></asp:LinkButton>
                </ContentTemplate>
            </asp:UpdatePanel>

            <asp:UpdatePanel ID="upnlJsRunner" UpdateMode="Always" runat="server">
                <ContentTemplate>
                    <asp:PlaceHolder ID="phrJsRunner" runat="server"></asp:PlaceHolder>
                </ContentTemplate>
            </asp:UpdatePanel>
            <br />
        </div>
    </form>

</asp:Content>
